home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / network / ka9q / ka9q_src.arc / AX25DUMP.C < prev    next >
Text File  |  1988-07-28  |  6KB  |  268 lines

  1. /* cat > ./ax25dump.c << '\Rogue\Monster\' */
  2. #include <stdio.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "ax25.h"
  6. #include "timer.h"
  7. #include "lapb.h"
  8. #include "trace.h"
  9.  
  10. #define    uchar(c)    (c & 0xff)
  11.  
  12. /*
  13. char
  14. uchar(c)
  15. char c;
  16. {
  17.     return (c & 0xff);
  18. }
  19. */
  20.  
  21. /* Dump an AX.25 packet header */
  22. ax25_dump(bpp,check)
  23. struct mbuf **bpp;
  24. int check;    /* Not used */
  25. {
  26.     char *decode_type();
  27.     char tmp[20];
  28.     char control,pid;
  29.     int16 type,ftype();
  30.     struct ax25 hdr;
  31.     struct ax25_addr *hp;
  32.  
  33.     printf("AX25: ");
  34.     /* Extract the address header */
  35.     if(ntohax25(&hdr,bpp) < 0){
  36.         /* Something wrong with the header */
  37.         printf(" bad header!\n");
  38.         return;
  39.     }
  40.     pax25(tmp,&hdr.source);
  41.     printf("%s",tmp);
  42.     pax25(tmp,&hdr.dest);
  43.     printf("->%s",tmp);
  44.     if(hdr.ndigis > 0){
  45.         printf(" v");
  46.         for(hp = &hdr.digis[0]; hp < &hdr.digis[hdr.ndigis]; hp++){
  47.             /* Print digi string */
  48.             pax25(tmp,hp);
  49.             printf(" %s%s",tmp,(hp->ssid & REPEATED) ? "*":"");
  50.         }
  51.     }
  52.     if(pullup(bpp,&control,1) != 1)
  53.         return;
  54.  
  55.     putchar(' ');
  56.     type = ftype(control);
  57.     printf("%s",decode_type(type));
  58.     /* Dump poll/final bit */
  59.     if(control & PF){
  60.         switch(hdr.cmdrsp){
  61.         case COMMAND:
  62.             printf("(P)");
  63.             break;
  64.         case RESPONSE:
  65.             printf("(F)");
  66.             break;
  67.         default:
  68.             printf("(P/F)");
  69.             break;
  70.         }
  71.     }
  72.     /* Dump sequence numbers */
  73.     if((type & 0x3) != U)    /* I or S frame? */
  74.         printf(" NR=%d",(control>>5)&7);
  75.     if(type == I || type == UI){    
  76.         if(type == I)
  77.             printf(" NS=%d",(control>>1)&7);
  78.         /* Decode I field */
  79.         if(pullup(bpp,&pid,1) == 1){    /* Get pid */
  80.             switch(pid & (PID_FIRST | PID_LAST)){
  81.             case PID_FIRST:
  82.                 printf(" First frag");
  83.                 break;
  84.             case PID_LAST:
  85.                 printf(" Last frag");
  86.                 break;
  87.             case PID_FIRST|PID_LAST:
  88.                 break;    /* Complete message, say nothing */
  89.             case 0:
  90.                 printf(" Middle frag");
  91.                 break;
  92.             }
  93.             printf(" pid=");
  94.             switch(pid & 0x3f){
  95.             case PID_ARP:
  96.                 printf("ARP\n");
  97.                 break;
  98.             case PID_NETROM:
  99.                 printf("NET/ROM\n");
  100.                 break;
  101.             case PID_IP:
  102.                 printf("IP\n");
  103.                 break;
  104.             case PID_NO_L3:
  105.                 printf("Text\n");
  106.                 break;
  107.             default:
  108.                 printf("0x%x\n",pid);
  109.             }
  110.             /* Only decode frames that are the first in a
  111.              * multi-frame sequence
  112.              */
  113.             switch(pid & (PID_PID | PID_FIRST)){
  114.             case PID_ARP | PID_FIRST:
  115.                 arp_dump(bpp);
  116.                 break;
  117.             case PID_IP | PID_FIRST:
  118.                 /* Only checksum complete frames */
  119.                 ip_dump(bpp,pid & PID_LAST);
  120.                 break;
  121.             case PID_NETROM | PID_FIRST:
  122.                 netrom_dump(bpp);
  123. nsport headers */
  124. static
  125. netrom_dump(bpp)
  126. struct mbuf **bpp;
  127. {
  128.     struct ax25_addr src,dest;
  129.     char x;
  130.     char tmp[16];
  131.     char thdr[5];
  132.     register i;
  133.  
  134.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  135.         return;
  136.     /* See if it is a routing broadcast */
  137.     if(uchar(*(*bpp)->data) == 0xff) {
  138.         pullup(bpp,tmp,1);        /* Signature */
  139.         pullup(bpp,tmp,ALEN);
  140.         tmp[ALEN] = '\0';
  141.         printf("NET/ROM Routing: %s\n",tmp);
  142.         for(i = 0;i < 11;i++) {
  143.             if (pullup(bpp,tmp,AXALEN) < AXALEN)
  144.                 break;
  145.             memcpy(src.call,tmp,ALEN);
  146.             src.ssid = tmp[ALEN];
  147.             pax25(tmp,&src);
  148.             printf("        %12s",tmp);
  149.             pullup(bpp,tmp,ALEN);
  150.             tmp[ALEN] = '\0';
  151.             printf("%8s",tmp);
  152.             pullup(bpp,tmp,AXALEN);
  153.             memcpy(src.call,tmp, ALEN);
  154.             src.ssid = tmp[ALEN];
  155.             pax25(tmp,&src);
  156.             printf("    %12s", tmp);
  157.             pullup(bpp,tmp,1);
  158.             printf("    %3u\n", (unsigned)uchar(tmp[0]));
  159.         }
  160.         return;
  161.     }
  162.     /* Decode network layer */
  163.     pullup(bpp,tmp,AXALEN);
  164.     memcpy(src.call,tmp,ALEN);
  165.     src.ssid = tmp[ALEN];
  166.     pax25(tmp,&src);
  167.     printf("NET/ROM: %s",tmp);
  168.  
  169.     pullup(bpp,tmp,AXALEN);
  170.     memcpy(dest.call,tmp,ALEN);
  171.     dest.ssid = tmp[ALEN];
  172.     pax25(tmp,&dest);
  173.     printf("->%s",tmp);
  174.  
  175.     pullup(bpp,&x,1);
  176.     printf(" ttl %d\n",uchar(x));
  177.  
  178.     printf("         ");
  179.     /* Read first five bytes of "transport" header */
  180.     pullup(bpp,thdr,5);
  181.     switch(thdr[4] & 0xf){
  182.     case 1:    /* Connect request */
  183.         printf("conn rqst: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  184.         pullup(bpp,&x,1);
  185.         printf(" wnd %d",x);
  186.         pullup(bpp,(char *)&src,sizeof(struct ax25_addr));
  187.         pax25(tmp,&src);
  188.         printf(" %s",tmp);
  189.         pullup(bpp,(char *)&dest,sizeof(struct ax25_addr));
  190.         pax25(tmp,&dest);
  191.         printf("->%s",tmp);
  192.         break;
  193.     case 2:    /* Connect acknowledgement */
  194.         printf("conn ack: ur ckt %d/%d my ckt %d/%d",
  195.             uchar(thdr[0]), uchar(thdr[1]), uchar(thdr[2]),
  196.             uchar(thdr[3]));
  197.         pullup(bpp,&x,1);
  198.         printf(" wnd %d",x);
  199.         break;
  200.     case 3:    /* Disconnect request */
  201.         printf("disc: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  202.         break;
  203.     case 4:    /* Disconnect acknowledgement */
  204.         printf("disc ack: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  205.         break;
  206.     case 5:    /* Information (data) */
  207.         printf("info: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  208.         printf(" txseq %d rxseq %d",uchar(thdr[2]), uchar(thdr[3]));
  209.         break;
  210.     case 6:    /* Information acknowledgement */
  211.         printf("info ack: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  212.         printf(" txseq %d rxseq %d",uchar(thdr[2]), uchar(thdr[3]));
  213.         break;
  214.     default:
  215.         /* maybe it's an IP datagram! */
  216.         /* the following is gross and disgusting */
  217.         {
  218.         struct mbuf *thbuf, *save ;
  219.         
  220.         if ((thbuf = alloc_mbuf(5)) == NULLBUF) break ;
  221.         thbuf->cnt = 5 ;
  222.         memcpy(thbuf->data,thdr,5) ;
  223.         save = *bpp ;
  224.         *bpp = thbuf ;
  225.         append(bpp,save) ;
  226.         ip_dump(bpp,1) ;
  227.         }
  228.         break;
  229.     }
  230.     if(thdr[4] & 0x80)
  231.         printf(" CHOKE");
  232.     if(thdr[4] & 0x40)
  233.         printf(" NAK");
  234.     printf("\n");
  235. }
  236. char *
  237. decode_type(type)
  238. int16 type;
  239. {
  240.     switch(uchar(type)){
  241.     case I:
  242.         return "I";
  243.     case SABM:
  244.         return "SABM";
  245.     case DISC:
  246.         return "DISC";
  247.     case DM:
  248.         return "DM";
  249.     case UA:
  250.         return "UA";
  251.     case RR:
  252.         return "RR";
  253.     case RNR:
  254.         return "RNR";
  255.     case REJ:
  256.         return "REJ";
  257.     case FRMR:
  258.         return "FRMR";
  259.     case UI:
  260.         return "UI";
  261.     default:
  262.         return "[invalid]";
  263.     }
  264. }
  265.  
  266.  
  267.  
  268.